﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Client
{
    public partial class FrmLogin : Form
    {
        private string ip = "127.0.0.1";
        private int port = 12345;

        public FrmLogin()
        {
            InitializeComponent();
        }

        private void BtnGoChat_Click(object sender, EventArgs e)
        {
            Lib.Client c = Lib.Client.GetInstance();
            c.Connect(ip, port);

            c.Send(TxtUserName.Text);
            c.ReceiveOk();

            Close();
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {

        }

        public string CheckInput(string input)
        {
            string str = "h" + input;
            char c = str.ToCharArray()[input.Length];
            if (Char.IsLetterOrDigit(c))
            {
                return input;
            }
            else
            {
                return input.Substring(0, input.Length - 1);
            }
        }

        private void TxtUserName_TextChanged(object sender, EventArgs e)
        {
            TxtUserName.Text = CheckInput(TxtUserName.Text);
            TxtUserName.Select(TxtUserName.Text.Length, 0);
        }
    }
}
